<!DOCTYPE html>  
<html>  
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>京东会员中心</title>
  <style>
	/* 全局样式 */
	body {
	  font-family: Arial, sans-serif;
	  margin: 0;
	  padding: 0;
	}
	
	header {
	  background-color: red;
	  padding: 10px;
	}
	
	nav ul {
	  list-style-type: none;
	  margin: 0;
	  padding: 0;
	}
	
	nav li {
	  display: inline-block;
	  margin-right: 10px;
	}
	
	nav li a {
	  color: #333;
	  text-decoration: none;
	  padding: 5px;
	}
	
	nav li a.active {
	  color: #fff;
	}
	
	main {
	  padding: 20px;
	}
	
	h2 {
	  margin-top: 0;
	}
	
	.profile-section {
	  margin-bottom: 20px;
	}
	
	.profile {
	  display: flex;
	  align-items: center;
	}
	
	.profile img {
	  width: 80px;
	  height: 80px;
	  border-radius: 50%;
	  margin-right: 20px;
	}
	
	.details p {
	  margin: 5px 0;
	}
	
	.orders-section {
	  margin-bottom: 20px;
	}
	
	table {
	  width: 100%;
	  border-collapse: collapse;
	}
	
	th, td {
	  padding: 10px;
	  text-align: left;
	  border-bottom: 1px solid #ddd;
	}
	
	tfoot {
	  font-weight: bold;
	}
	
	footer {
	  background-color: red;
	  color: #fff;
	  padding: 10px;
	  text-align: center;
	}


	  .nav-item ul li a {
		  color: #fff;
		  text-decoration: none; 
	  }
	  .nav-item ul li a:hover{
		  color: #ff0; /* 鼠标悬停时的文本颜色 */  
	  }
  </style>
</head>
<body>
  <header>
    <h3>会员中心</h3>
    <nav class="nav-item">
      <ul>
        <li><a href="../index.html">首页</a></li>
        <li><a href="#">购物车</a></li>
        <li><a href="#">我的订单</a></li>
        <li><a class="active" href="#">会员中心</a></li>
        <li><a href="../index.html">退出登录</a></li>
      </ul>
    </nav>
  </header>

  <main>
    <section class="profile-section">
      <h2>个人资料</h2>
      <div class="profile">
        <img src="../img/avatar.png" alt="会员头像">
        <div class="details">
          <p><strong>用户名:</strong> <span id="username">JohnDoe</span></p>
          <p><strong>Email:</strong> <span id="email">johndoe@example.com</span></p>
          <p><strong>手机号码:</strong> <span id="phone">123-456-7890</span></p>
          <button onclick="editProfile()">编辑资料</button>
          <button onclick="saveProfile()">保存</button>
        </div>
      </div>
    </section>

    <section class="orders-section">
      <h2>订单历史</h2>
      <table>
        <thead>
          <tr>
            <th>订单编号</th>
            <th>商品</th>
            <th>数量</th>
            <th>金额</th>
          </tr>
        </thead>
        <tbody id="orderHistory">
          <!-- 订单行将在JavaScript代码中生成 -->
        </tbody>
      </table>
    </section>
  </main>

  <footer>
    <p>&copy; 2022 在线商城.</p>
  </footer>

  <script>
    // 编辑个人资料
    function editProfile() {
      document.getElementById("username").contentEditable = true;
      document.getElementById("email").contentEditable = true;
      document.getElementById("phone").contentEditable = true;
      document.getElementById("username").focus();
      document.getElementById("email").focus();
      document.getElementById("phone").focus();
      document.getElementById("username").style.border = "1px solid #ccc";
      document.getElementById("email").style.border = "1px solid #ccc";
      document.getElementById("phone").style.border = "1px solid #ccc";
      document.getElementById("username").style.padding = "5px";
      document.getElementById("email").style.padding = "5px";
      document.getElementById("phone").style.padding = "5px";
      document.getElementById("username").style.outline = "none";
      document.getElementById("email").style.outline = "none";
      document.getElementById("phone").style.outline = "none";
      document.getElementById("username").setAttribute("contenteditable", "true");
      document.getElementById("email").setAttribute("contenteditable", "true");
      document.getElementById("phone").setAttribute("contenteditable", "true");
      document.getElementById("editProfileBtn").style.display = "none";
      document.getElementById("saveProfileBtn").style.display = "inline-block";
    }

    // 保存个人资料
    function saveProfile() {
      document.getElementById("username").contentEditable = false;
      document.getElementById("email").contentEditable = false;
      document.getElementById("phone").contentEditable = false;
      document.getElementById("username").style.border = "none";
      document.getElementById("email").style.border = "none";
      document.getElementById("phone").style.border = "none";
      document.getElementById("username").style.padding = "0";
      document.getElementById("email").style.padding = "0";
      document.getElementById("phone").style.padding = "0";
      document.getElementById("username").removeAttribute("contenteditable");
      document.getElementById("email").removeAttribute("contenteditable");
      document.getElementById("phone").removeAttribute("contenteditable");
      document.getElementById("editProfileBtn").style.display = "inline-block";
      document.getElementById("saveProfileBtn").style.display = "none";
    }

    // 绑定订单历史
    // 这里仅是示例数据，实际应从后端获取数据，生成相应的订单行
    var orderData = [
      // { orderId: "123456", product: "iPhone 12", quantity: 1, amount: "$999.99" },
      // { orderId: "789012", product: "iPad Pro", quantity: 2, amount: "$1599.99" }
    ];

    var orderHistory = document.getElementById("orderHistory");
    for (var i = 0; i < orderData.length; i++) {
      var row = document.createElement("tr");
      row.innerHTML = `
        <td>${orderData[i].orderId}</td>
        <td>${orderData[i].product}</td>
        <td>${orderData[i].quantity}</td>
        <td>${orderData[i].amount}</td>
      `;
      orderHistory.appendChild(row);
    }
  </script>
</body>